package com.edgclub.edg.adapter;

import android.app.Activity;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.edgclub.edg.R;
import com.edgclub.edg.adapter.adapteruitls.GzBaseAdapter;
import com.edgclub.edg.adapter.adapteruitls.MyItemClickListener;
import com.edgclub.edg.adapter.adapteruitls.MyItemLongClickListener;
import com.edgclub.edg.adapter.adapteruitls.RViewHolder;
import com.edgclub.edg.model.result.EDGTeamData;
import com.edgclub.edg.utils.GlideUtil.GlideUtils;
import com.edgclub.edg.utils.util.DensityUtils;

import java.util.ArrayList;

/**
 */
public class EDGTeamAdapter extends GzBaseAdapter {
    private Context mContext;

    private ArrayList<EDGTeamData.Team> list;

    private GlideUtils glideUtils;
    private int width;


    public EDGTeamAdapter(Context mContext) {
        this.mContext = mContext;
        glideUtils = new GlideUtils();
        width =(DensityUtils.getScreenW((Activity) mContext) - DensityUtils.dip2px(mContext,30))/2;
    }

    public ArrayList<EDGTeamData.Team> getList() {
        return list;
    }

    public void setList(ArrayList<EDGTeamData.Team> list) {
        this.list = list;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_edg_team,viewGroup,false);
        ViewHolder vh = new ViewHolder(view,mListener,mLongClickListener);
        return vh;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        ViewHolder viewHolder = (ViewHolder) holder;
        ViewGroup.LayoutParams params = viewHolder.imgv_icon.getLayoutParams();
        params.width = width;
//        params.height = width;
        viewHolder.imgv_icon.setLayoutParams(params);
        glideUtils.Glidde_loadImagefitCenter(mContext, list.get(position).getLogo(), viewHolder.imgv_icon);
    }

    @Override
    public long getItemId(int arg0) {
        return 0;
    }

    @Override
    public int getItemCount() {
        return list.size();
    }


    //自定义的ViewHolder，持有每个Item的的所有界面元素
    public static class ViewHolder extends RViewHolder {
        public ImageView imgv_icon;

        public ViewHolder(View view, MyItemClickListener mListener, MyItemLongClickListener mLongClickListener){
            super(view,mListener,mLongClickListener);
            imgv_icon = (ImageView) view.findViewById(R.id.imgv_icon);
        }
    }

}
